package com.controller;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.entity.Question;
import com.service.QuestionService;

@Controller
@RequestMapping("/question")
public class QuestionController {

	@Resource
	QuestionService qs;
	
	@ResponseBody
	@RequestMapping("/list")
	public Map list(@RequestParam(defaultValue="1") int page,@RequestParam(defaultValue="5") int rows,Question q){
		Map<String, Object> m = new HashMap<String, Object>();
		m.put("pageStart", (page-1)*rows);
		m.put("pageSize", rows);
		m.put("param",q);
		m = qs.list(m);
		System.out.println(m);
		return m;
	}
	
	@ResponseBody
	@RequestMapping(value="/add",produces="text/html;charset=utf-8")
	public String add(Question q){
		if(qs.add(q)){
			return "新增成功！";
		}
		return "新增失败！请重试！";
	}
	@ResponseBody
	@RequestMapping("/get")
	public Question get(@RequestParam(required=true)int id){
		Question q = qs.get(id);
		return q;
	}
	
	@ResponseBody
	@RequestMapping(value="/edit",produces="text/html;charset=utf-8")
	public String edit(Question q){
		if(qs.edit(q)){
			return "修改成功！";
		}
		return "修改失败！请重试！";
	}
	
	@ResponseBody
	@RequestMapping(value="/delete",produces="text/html;charset=utf-8")
	public String delete(@RequestParam(required=true)int id){
		if(qs.delete(id)){
			return "删除成功！";
		}
		return "删除失败！请重试！";
	}
}
